package com.whalehearing.tingyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whalehearing.tingyou.domain.HearingImg;
import com.whalehearing.tingyou.mapper.HearingImgMapper;
import com.whalehearing.tingyou.service.IHearingImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 听力图Service业务层处理
 *
 * @author zengjun-qxm
 * @date 2024-09-13
 */
@Service
public class HearingImgServiceImpl extends ServiceImpl<HearingImgMapper, HearingImg> implements IHearingImgService {

    @Autowired
    private HearingImgMapper hearingImgMapper;


    /**
     * 新增听力图
     */
    @Override
    public void saveHearingImg(List<HearingImg> hearingImg) {
        for (HearingImg data : hearingImg) {
            hearingImgMapper.insert(data);
        }
    }

    /**
     * 查询听力图列表
     *
     * @param hearingImg 听力图
     * @return 听力图
     */
    @Override
    public List<HearingImg> selectHearingImgList(HearingImg hearingImg) {
        List<HearingImg> hearingImgList = hearingImgMapper.selectList(buildQueryWrapper(hearingImg));
        return hearingImgList;
    }


    private LambdaQueryWrapper<HearingImg> buildQueryWrapper(HearingImg query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<HearingImg> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getAudiogramId() != null, HearingImg::getAudiogramId, query.getAudiogramId());
        lqw.orderByDesc(HearingImg::getCreateTime);
        lqw.eq(query.getIsDeleted() != null, HearingImg::getIsDeleted, query.getIsDeleted());
        return lqw;
    }

}
